package com.boot.controller;

import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.boot.entity.Result;
import com.boot.entity.Share;
import com.boot.service.IShareService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author bbyh
 * @since 2024-04-29
 */
@RestController
@RequestMapping("/share")
@Api("/分享接口")
@Slf4j
public class ShareController {
    @Resource
    private IShareService shareService;

    @ApiOperation("分享列表获取接口")
    @PostMapping("/getShareList")
    public Result getShareList(@RequestBody Map<String, Object> map) {
        try {
            Integer current = (Integer) map.get("current");
            Integer pageSize = (Integer) map.get("pageSize");

            Page<Share> page = new Page<>(current, pageSize);
            Page<Share> sharePage = shareService.page(page);
            JSONObject jsonObject = new JSONObject();
            jsonObject.putOnce("shareList", sharePage.getRecords());
            jsonObject.putOnce("total", sharePage.getTotal());
            return Result.success(jsonObject, "图标列表获取成功");
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return Result.error("图标列表获取接口服务出错", null);
        }
    }
}
